/**
 * @author Mie Plougstrup, Anders Abildgaard, Bo Stokholm 
 * @Version 16-12-2014
 */

package tests;

import static org.junit.Assert.fail;

import java.sql.Date;
import java.util.ArrayList;

import modelLayer.DispositionList;

import org.junit.Test;

import dbLayer.DbDispositionList;
import dbLayer.DbMaxId;

public class TestDbDispositionList {
	
	DbDispositionList dbDL = new DbDispositionList();
	DispositionList dpltestObj = new DispositionList(new Date(2014, 11, 16));
	
	/**
	 * Test if its possible to retrieve a disposition list by id
	 */
	@Test
	public void testRetrieveById() {
		if(dbDL.retrieveById(1, false).getDispListId() == 1) {
			System.out.println("RetrieveById succes");
		} else {
			fail("RetrieveById failed");
		}
	}
	/**
	 * Retrieve disposition list by date.
	 * **********************************
	 */
	@Test
	public void testRetrieveByDate() {
		dpltestObj.setDispListId(DbMaxId.getMaxID("dispListId", "dispositionList") + 1);
		if(dbDL.retrieveByDate(new Date(2014, 11, 16)).getDispListId() > 0) {
			System.out.println("RetrieveByDate succes");
		} else {
			fail("RetrieveByDate failed");
		}
	}
	/**
	 * Test the following methods:
	 * Insert dispositionList
	 * Update dispositionList
	 * Delete dispositionList
	 */
	@Test
	public void testInsertUpdateDelete() {
		dpltestObj.setDispListId(DbMaxId.getMaxID("dispListId", "dispositionList") + 1);
		dbDL.retrieveById(1, true).printToFile();
		try {
			dbDL.insert(dpltestObj);
			dbDL.update(dpltestObj);
			dbDL.delete(dpltestObj);
			System.out.println("InsertUpdateDelete succes");
		} catch (Exception e) {
			fail("InsertUpdateDelete failed");
		}	
	}
	
	/**
	 * Retrieve all undone disposition lists
	 */
	@Test
	public void testRetrieveAllUnDone(){
		ArrayList<DispositionList> list = new ArrayList<DispositionList>();
		try{
		list = dbDL.retrieveUndone(false);
		if(list.size() > 0)
			System.out.println("Successfully retrieved all undone lists.");
		else
			fail("Failed to retrieve all undone disposition lists.");
		}catch(Exception e){
			fail("Failed to retrieve all undone disposition lists.");
		}
	}
}
